package com.imooc.hystrix.service;

import com.imooc.hystrix.bean.Friend;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class RequestCacheService {

    @CacheResult
    @HystrixCommand(
//            指定降级方法，统计类中声明  abc 方法为降级函数，参数必须相同
            fallbackMethod = "abc",
// 方法签名，针对某个方法的超时配置 的签名，这里可以声明 独特的 签名名称
            commandKey = "cacheKey",
            commandProperties = {
                    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "")
            }
    )
    public Friend requestCache(@CacheKey String name){
       log.info("requestCache "+name);
        Friend friend = new Friend();
        friend.setName(name);

        log.info("after requestCache "+name);
        return friend;
    }

 

}
